package tools

import (
	"fmt"
	"zzxq/common/setting"

	//openapi "github.com/alibabacloud-go/darabonba-openapi/client"
	dysmsapi20170525 "github.com/alibabacloud-go/dysmsapi-20170525/client"
	"github.com/alibabacloud-go/tea-rpc/client"
	"github.com/alibabacloud-go/tea/tea"
)

// 依赖的模块可通过下载工程中的模块依赖文件或右上角的获取 SDK 依赖信息查看
/**
 * 使用AK&SK初始化账号Client
 * @param accessKeyId
 * @param accessKeySecret
 * @return Client
 * @throws Exception
 */
func CreateClient(accessKeyId *string, accessKeySecret *string) (_result *dysmsapi20170525.Client, _err error) {
	config := &client.Config{
		// 您的AccessKey ID
		AccessKeyId: accessKeyId,
		// 您的AccessKey Secret
		AccessKeySecret: accessKeySecret,
	}
	// 访问的域名
	config.Endpoint = tea.String("dysmsapi.aliyuncs.com")
	_result = &dysmsapi20170525.Client{}
	_result, _err = dysmsapi20170525.NewClient(config)
	return _result, _err
}

func SendAliSms(phoneNum string, checkCode string) bool {
	client, _err := CreateClient(tea.String("LTAI5tAdFU9ZpBccKgGEnzYu"), tea.String("pPGLiAgTipe34eQ4iQSfDzPyizVtnS"))
	if _err != nil {
		fmt.Println(_err)
		return false
	}
	conf := setting.Config.AliSms
	sendSmsRequest := &dysmsapi20170525.SendSmsRequest{
		PhoneNumbers:  tea.String(phoneNum),
		SignName:      tea.String(conf.SignName),
		TemplateCode:  tea.String(conf.TemplateCode),
		TemplateParam: tea.String(checkCode),
	}
	// 复制代码运行请自行打印 API 的返回值
	_, _err = client.SendSms(sendSmsRequest)
	if _err != nil {
		fmt.Println(_err)
		//logger.ILogger.Errorf("发送短信失败","",_err)
		return false
	} else {
		return true
	}
	return true
}
